/**
 * Created by oneminute on 2014/5/18.
 */

var moment = require("moment");
var lz = require("../utils/modules")();

function Demand(_opts) {
    lz.Persistent.call(this, _opts);
    if (!_opts) _opts = {};
    var now = moment();
    this.__properties.pushArray([
        { name: "id", value: _opts.id || "" },
        { name: "uid", value: _opts.uid || "" },
        { name: "description", value: _opts.description || "" },
        { name: "finished", value: false },
        { name: "publishDate", value: _opts.publishDate || now.format(lz.Config.datetimeFormat) },
        { name: "expireDate", value: _opts.expireDate || now.add('d', lz.Config.business.needExpire).format(lz.Config.datetimeFormat) }
    ]);
    this.__initProperties();
    this.__collection = lz.Config.db.arango.demands;
    this.__aql = lz.Config.db.arango.aqls.GET_OBJECT_BY_PROPERTY;
}

require("util").inherits(Demand, lz.Persistent);

Demand.prototype.getInfo = function (_user) {
    var obj = this.getFields(['id', 'uid', 'description', 'finished', 'publishDate', 'expireDate']);
    if (_user) {
        //obj.photo = lz.ImageManager.getPhoto(_user.photo, 't');
        obj.photo = _user.photo;
    }
    return obj;
};

exprots = module.exports = Demand;
